package com.szmirren.vxApi.spi.handler;

import java.util.ArrayList;
import java.util.List;

import com.szmirren.vxApi.core.common.StrUtil;
import com.szmirren.vxApi.core.entity.VxApis;

import com.szmirren.vxApi.spi.handler.impl.TestAfterHandlerSimple;
import io.vertx.core.http.HttpClient;
import io.vertx.core.json.JsonObject;

/**
 * @author <a href="http://szmirren.com">Mirren</a>
 */
public class VxApiAfterHandlerFactory {

    /**
     * 后置处理器实现类的名字（页面中的value调用这个变量值）
     */
    public final static String TEST_AFTER_HANDLER_SIMPLE = "testAfterHandlerSimple";

    /**
     * 获得所有实现类名字
     *
     * @return
     */
    public static List<String> getImplNames() {
        List<String> result = new ArrayList<>();
        result.add(TEST_AFTER_HANDLER_SIMPLE);
        return result;
    }

    /**
     * 获得后置处理器
     *
     * @param name 后置处理器名称
     * @param options 后置处理器配置文件
     * @param httpClient httpClient
     * @return VxApiAfterHandler
     * @throws NullPointerException
     * @throws ClassNotFoundException
     */
    public static VxApiAfterHandler getAfterHandler(String name, JsonObject options, VxApis api, HttpClient httpClient)
            throws NullPointerException, ClassNotFoundException {
        if (StrUtil.isNullOrEmpty(name)) {
            throw new NullPointerException("获取后置处理器实现-->失败:工厂名字不能为空");
        }
        if (TEST_AFTER_HANDLER_SIMPLE.equalsIgnoreCase(name)) {
            return new TestAfterHandlerSimple(api,options,httpClient);
        }
        throw new ClassNotFoundException("没有找到名字为 : " + name + " 的后置处理器实现类");
    }

}
